package com.qingfeng.qfcms.service.impl;

import com.qingfeng.qfcms.common.encode.Md5PwdImpl;
import com.qingfeng.qfcms.dao.UserDao;
import com.qingfeng.qfcms.domin.User;
import com.qingfeng.qfcms.page.Page;
import com.qingfeng.qfcms.service.UserService;
import com.qingfeng.qfcms.utils.MD5;
import com.qingfeng.qfcms.utils.PageData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * 用户信息
 * Created by User on 2016/7/20.
 */
@Service
public class UserServiceImpl implements UserService {


    @Autowired
    private UserDao userDao;
    @Autowired
    private Md5PwdImpl md5Pwd;
    public List<User> findPage(Page page) {
        return userDao.findPageList(page);
    }

    public List<User> find(Map paraMap) {
        return userDao.find(paraMap);
    }

    public List<User> list(Map paraMap) {
        return userDao.list(paraMap);
    }

    public User get(Serializable id) {
        return userDao.get(id);
    }

    public void insert(User entity) {

        userDao.insert(entity);
    }

    public void update(User entity) {
        if(!"".equals(entity.getPASSWORD())){
            System.out.println(entity.getPASSWORD());
            entity.setPASSWORD(MD5.md5("mengxiaodong@126.com"+entity.getPASSWORD()));
        }
        userDao.update(entity);
    }

    public void deleteById(Serializable id) {
       userDao.deleteById(id);
    }

    public void delete(Serializable[] ids) {
       userDao.delete(ids);
    }

    public User checkName(String name,String password) {
        List<User> user=userDao.checkName(name);
        if (user.size()>0){
             User user1=user.get(0);
            String pas="mengxiaodong@126.com"+password;
             if (user1.getPASSWORD().equals(MD5.md5(pas))){
                 return user1;
             }else{
                 return null;
             }
        }else {
            return null;
        }
    }

    public List<User> findUserRoleOrganizationList(Page page) {
        return userDao.findUserRoleOrganizationList(page);
    }

    public User findById(String id) {
        return userDao.findById(id);
    }

    public int updateIp(User user) {
        int i=userDao.updateIp(user);
        return i;
    }

    public List<PageData> findPd(PageData pd) {
        return userDao.findPd(pd);
    }
}
